using B.S.Data.MES.API.Applications.CangKu.Command;
using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    public class DeleteCangKuQUCommandHandler : IRequestHandler<DeleteCangKuQUCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<CangKuQU> _cangKuQURepository;

        public DeleteCangKuQUCommandHandler(IBaseRepository<CangKuQU> cangKuQURepository)
        {
            _cangKuQURepository = cangKuQURepository;
        }

        public async Task<APIRequst<int>> Handle(DeleteCangKuQUCommand request, CancellationToken cancellationToken)
        {
            var cangKuQU = await _cangKuQURepository.GetById(request.CangKuId);
            cangKuQU.isDel = true;
            var result = await _cangKuQURepository.Update(cangKuQU);
            
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = "删除成功",
                Data = result
            };
        }
    }
}